<%--                                                                       --%>
<%-- Copyright (c) 2003-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import = "java.util.*,
                   com.broadvision.ssp.common.NotifyRuntimeSpec,
                   com.broadvision.ssp.common.NotifyType"
%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<jsp:useBean id="processInstanceTasksForm" 
          class="com.broadvision.process.tools.action.process.ProcessInstanceTasksForm"
          scope="session"/>

<script language="JavaScript" src="<%=request.getContextPath()%>/bp/js/user_popup_funcs.js"></script>
<script language="JavaScript" type="text/JavaScript">

<!--
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function getTimeStamp() {
    var now = new Date;
    var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() + 
      now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();
    return timestamp;
}
function searchUserPopup(popupUrl, parentFormName, parentFieldName) {
    var timestamp = getTimeStamp();
    if (popupUrl != null) {
      if (popupUrl.indexOf("?") < 0) {
        popupUrl += "?";
      } 
      else {
        popupUrl += "&";
      }
    }
    popupUrl += 'timestamp=' + timestamp + '&parentFormName=' + parentFormName +
      '&parentFieldName=' + parentFieldName;
    var thisForm = document.forms[parentFormName];
    var elements = thisForm.elements;
    var numElements = elements.length;
    var field = null;
    for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
      var elementName = elements[elementIndex].name;
      if (elementName == parentFieldName) {
        field = elements[elementIndex];
        break;
      }
    }
    if (field != null && field.length > 0) {
      var selectedusers = '&selected=';
      for (var i = 0; i < field.length; i++) {
        selectedusers += field.options[i].value;
        if (i != field.length - 1) {
          selectedusers += '%24%23@!';
        }
      }
      popupUrl += selectedusers;
    }
    var windowName = parentFormName + parentFieldName;
    var windowFeatures = 'width=700,height=600,scrollbars=yes,resizable=yes';
    var popupWindow = window.open(popupUrl, windowName, windowFeatures);
    if (popupWindow != null) {
      if (popupWindow.opener == null) {
        popupWindow.opener = self;
      }
    }
    popupWindow.focus();
  }
  
  function checkNumberOnly(e) {
    var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
      return false;
    }
    else {
      return true;
    }
  }

function validateForm(myform)
{   
    var days = myform.elements["reminderDays"];
    var hours = myform.elements["reminderHours"];
    if (days != undefined) {
      var daysInt = parseInt(days.value, 10);
      var hoursInt = parseInt(hours.value, 10);
      if (isNaN(daysInt)) {
        alert('<bean:message key="bp.process.processInstanceNotifyNew.days" bundle="bp.messages"/>');
        return false;
      }
      if (isNaN(hoursInt)) {
        alert('<bean:message key="bp.process.processInstanceNotifyNew.hour" bundle="bp.messages"/>');
        return false;
      }
      if (daysInt == 0 && hoursInt == 0) {
        alert('<bean:message key="bp.process.error.invalidNoticeTime" bundle="bp.messages"/>');
        return false;
      }
      if (hoursInt < 0 || hoursInt > 23) {
        alert('<bean:message key="bp.process.processInstanceNotifyNew.hourRange" bundle="bp.messages"/>');
        return false;
      }
      if (daysInt < 0 || daysInt > 24854) {
        alert('<bean:message key="bp.process.processInstanceNotifyNew.dayRange" bundle="bp.messages"/>');
        return false;
      }
    }
    return true;
}
function setSelectedUsers(formName, fieldName, users) {
    var thisForm = document.forms[formName];
    var elements = thisForm.elements;
    var numElements = elements.length;
    var field = null;
    for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
      var elementName = elements[elementIndex].name;
      if (elementName == fieldName) {
        field = elements[elementIndex];
        break;
      }
    }
    if (field != null) {
      var numOriginalUsers = field.length;
      if (users != null) {
        var numUsers = users.length;
        var i = 0;
        for (i = 0; i < numUsers; i++) {
          if (i >= numOriginalUsers) {
            var newoption = new Option(users[i], users[i], true, true);
            field.options[i] = newoption;
          }
          else {
            field.options[i].text = users[i];
            field.options[i].value = users[i];
            field.options[i].defaultSelected = true;
            field.options[i].selected = true;
          }
        }
        for (var j = numOriginalUsers - 1; j >= i; j--) {
          field.options[j] = null;
        }
      }
      else {
        for (var i = numOriginalUsers - 1; i >= 0; i--) {
          field.options[i] = null;
        }
      }
    }
  }
function doReset(myform) {
 myform.action = '<html:rewrite page="/bp/processInstanceNotification.do?action=edit"/>';
 myform.submit();
}

function doCancel(myform) {
 myform.action = '<html:rewrite page="/bp/processInstanceNotification.do"/>';
 myform.submit();
}

//-->
</script>

<% java.util.HashMap map= new java.util.HashMap();
   String instanceOid = request.getParameter("instanceOid"); 
   if (instanceOid!=null && instanceOid.length()>0)
        map.put("instanceOid",instanceOid);
   map.put("currentTask",request.getParameter("currentTask"));
   pageContext.setAttribute("pagetabParam",map);
%>
<html:form action="/bp/processInstanceNotification.do?action=update"  onsubmit="return validateForm(this);" >
<input type="hidden" name="currentTask" value="<%=((HashMap)pageContext.getAttribute("pagetabParam")).get("currentTask")%>" />
<html:hidden name="processInstanceTasksForm" property="notifyIndex" />
    <table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean:message key="bp.process.processInstance.contentArea" bundle="bp.messages"/>">
      <tr>
        <td valign="top" width="100%">
          <div class="pageTitle"><bean:write name="processInstanceTasksForm" property="currentMinorTask" />
          </div>
          <%@include file="/mc/common/pagetab.jsp" %>
        <div class="breadcrumb">
          <html:link page="/bp/processInstanceTasks.do"  paramId="instanceOid" paramName="processInstanceTasksForm"  paramProperty="instanceOid"><bean:write name="bpProcessInstanceForm" property="processInstance.customId" /></html:link>&nbsp;>&nbsp;<bean:write name="processInstanceTasksForm" property="currentMinorTask" /></div>
          <div class="pageSubtitle">
            <span class="left"><bean:message key="bp.process.processInstanceNotifyNew.title" bundle="bp.messages"/></span>
          </div> 
          <table class="dataTable" border="0" cellspacing="0" cellpadding="0" summary="<bean:message key="bp.process.processInstanceNotifyNew.summary" bundle="bp.messages"/>" width="100%">        
            <tr><td class="errorMessage" colspan="2"><html:errors bundle="bp.messages"/></td></tr>
            <tr>
                <td valign="top" nowrap class="label" width="18%"><bean:message key="bp.process.processInstanceNotifyNew.notifyType" bundle="bp.messages"/></td>
                <td valign="top" nowrap class="labelField" width="40%">
            <bean:message key="<%=\"bp.process.processInstanceNotify.\"+((NotifyRuntimeSpec)(processInstanceTasksForm.getNotifySpec()[processInstanceTasksForm.getNotifyIndex()]).get(0)).getNotifyType().toString()%>" bundle="bp.messages"/>
                </td>
            </tr>
            <tr>
                <td valign="top" nowrap class="label" width="18%"><bean:message key="bp.process.processInstanceNotifyNew.deliveryType" bundle="bp.messages"/></td>
                <td valign="top" nowrap class="labelField" width="40%">
                   <bean:message key="<%=\"bp.process.processInstanceNotify.\"+((NotifyRuntimeSpec)(processInstanceTasksForm.getNotifySpec()[processInstanceTasksForm.getNotifyIndex()]).get(0)).getDeliveryType().toString()%>" bundle="bp.messages"/>                </td>
            </tr>

        <% if(((NotifyRuntimeSpec)(processInstanceTasksForm.getNotifySpec()[processInstanceTasksForm.getNotifyIndex()]).get(0)).getNotifyType()==NotifyType.REMINDERNOTIFICATION) { %>
          <tr> 
            <td class="label" width="18%">
              <bean:message key="bp.process.processTaskAlert.noticeTime" bundle="bp.messages"/>
            </td>
            <td class="labelField" width="40%">
              <html:text name="processInstanceTasksForm" property="reminderDays" size="5" maxlength="5" onkeypress="return checkNumberOnly(event)"/>
              <bean:message key="bp.process.unit.days" bundle="bp.messages"/>
              &nbsp;
              <html:text name="processInstanceTasksForm" property="reminderHours" size="2" maxlength="2" onkeypress="return checkNumberOnly(event)"/>
              <bean:message key="bp.process.unit.hours" bundle="bp.messages"/>
            </td>
          </tr>
<% } %>
            <tr>
                <td valign="top" nowrap class="label" width="18%"><bean:message key="bp.process.processInstanceNotifyNew.userToNotify" bundle="bp.messages"/></td>
                <td valign="top" nowrap class="labelField" width="40%">
                <% processInstanceTasksForm.setRecipients(new String[0]);
%>
                    <html:select name="processInstanceTasksForm" property="recipients" size="4" multiple="true">
              <html:optionsCollection name="processInstanceTasksForm" property="recipientsList"/>
                    </html:select>
                    <input type="button" name="browseUsers" class="pageButton"
              onClick="JavaScript:searchUserPopup('<html:rewrite page="/mt/userMultiSearchPopup.do"/>', 'processInstanceTasksForm', 'recipients')"
              value='<bean:message key="button.browse" bundle="bp.messages"/>' >
              
                </td>
            </tr>
        </table>
      <div class="pageButtonWrap" align="right">
        <input type="button" name="resetData" class="pageButton" 
          onClick="doReset(this.form);" 
          value='<bean:message key="button.reset" bundle="bp.messages"/>'>
        &nbsp;
        <input type="button" name="cancelData" class="pageButton" 
          onClick="doCancel(this.form);" 
          value='<bean:message key="button.cancel" bundle="bp.messages"/>'>
        <input type="submit" name="saveData" class="pageButton" 
          value='<bean:message key="button.save" bundle="bp.messages"/>'>
      </div>
        </td>
      </tr>
    </table>
<script language="JavaScript" type="text/JavaScript">
var r = document.processInstanceTasksForm.elements["recipients"];
if (r != null) {
    var num = r.length;
    var i = 0;
    for (i = 0; i < num; i++) {
        r.options[i].selected = true;
    }
}

</script>
  </html:form>

